//
//  DYEssenceCell.m
//  BaiSi
//
//  Created by mac on 16/10/29.
//  Copyright © 2016年 DeYi. All rights reserved.
//

#import "DYEssenceCell.h"
#import "DYTopView.h"
#import "DYThemeViewModel.h"
#import "DYThemePhotoView.h"
#import "DYThemeItem.h"
#import "DYThemeVoiceView.h"
#import "DyThemeVedioView.h"
#import "DYThemeHotReview.h"
#import "DYBottomView.h"


@interface DYEssenceCell ()

@property(nonatomic,weak) DYTopView *topView;
@property(nonatomic,weak) DYThemePhotoView *photoView;
@property(nonatomic,weak) DYThemeVoiceView *voiceView;
@property(nonatomic,weak) DYThemeVedioView *vedioView;
@property(nonatomic,weak) DYThemeHotReview *hotReview;
@property(nonatomic,weak) DYBottomView *bottomView;

@end

@implementation DYEssenceCell



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setFrame:(CGRect)frame {
    frame.origin.y += 10;
    frame.size.height -=10;
    
    [super setFrame:frame];
}





//初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIImage *image = [UIImage imageNamed:@"mainCellBackground"];
        image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
        self.backgroundView = [[UIImageView alloc] initWithImage:image];
        
        //顶部
        DYTopView *topView = [DYTopView ViewFromXib];
        [self.contentView addSubview:topView];
        _topView = topView;
       
        //中间
        //图片
        DYThemePhotoView *photoView = [DYThemePhotoView ViewFromXib];
        [self.contentView addSubview:photoView];
        _photoView = photoView;
        
        //声音
        DYThemeVoiceView *voiceView = [DYThemeVoiceView ViewFromXib];
        [self.contentView addSubview:voiceView];
        _voiceView = voiceView;
        
        //视频
        DYThemeVedioView *vedioView = [DYThemeVedioView ViewFromXib];
        [self.contentView addSubview:vedioView];
        _vedioView = vedioView;
        
        //段子
        
        //最热评论
        DYThemeHotReview *hotReview = [DYThemeHotReview ViewFromXib];
        [self.contentView addSubview:hotReview];
        _hotReview = hotReview;
        
        //底部
        DYBottomView *bottomView = [DYBottomView ViewFromXib];
        [self.contentView addSubview:bottomView];
        _bottomView = bottomView;
    }
    
    return self;
}

-(void)setViewModel:(DYThemeViewModel *)viewModel {
    _viewModel = viewModel;
    
    //顶部View
    _topView.frame = viewModel.topViewFrame;
    _topView.item = viewModel.item;
    
    //中间视图
    if (viewModel.item.type == MyPhotoType) {//图片
        _photoView.hidden = NO;
        _voiceView.hidden = YES;
        _vedioView.hidden = YES;
        _photoView.frame = viewModel.middleViewFrame;
        _photoView.item = viewModel.item;
        
        
        
    } else if (viewModel.item.type == MyVoiceType) {//声音
        _photoView.hidden = YES;
        _voiceView.hidden = NO;
        _vedioView.hidden = YES;
        _voiceView.frame = viewModel.middleViewFrame;
        _voiceView.item = viewModel.item;
        
    } else if (viewModel.item.type == MyVedioType) {//视频
        _photoView.hidden = YES;
        _voiceView.hidden = YES;
        _vedioView.hidden = NO;
        _vedioView.frame = viewModel.middleViewFrame;
        _vedioView.item = viewModel.item;
        
    } else if (viewModel.item.type == MyTextType) {//段子
        _photoView.hidden = YES;
        _voiceView.hidden = YES;
        _vedioView.hidden = YES;
        
    }
    
    //最热评论
    if (viewModel.item.hotItem) {
        _hotReview.hidden = NO;
        _hotReview.frame = viewModel.HotReviewFrame;
        _hotReview.item = viewModel.item;
    } else {
        _hotReview.hidden = YES;
    }
    
    //底部视图
    _bottomView.frame = viewModel.bottomViewFrame;
    _bottomView.item = viewModel.item;
   
}


@end
